#ifndef _EVENTLOOP_H_
#define _EVENTLOOP_H_

#include <vector>
#include <memory>
#include <map>
#include <sys/epoll.h>

using namespace std;

class Acceptor;
class TcpConnection;

class EventLoop
{
    using TcpConnectionPtr = shared_ptr<TcpConnection>;
public:
    EventLoop(Acceptor & acceptor);
    ~EventLoop();

    void loop();
    void unloop();
private:
    void waitEpollFd();

    void handleNewConnection();

    void handleMessage(int fd);
    //创建epfd
    int createEpollFd();

    //监听文件描述符
    void addEpollReadFd(int fd);

    //取消监听文件描述符
    void delEpollReadFd(int fd);
private:
    int _epfd;
    vector<struct epoll_event> _evtList;
    bool _isLooping;
    Acceptor &_acceptor;
    map<int,TcpConnectionPtr> _conns;
};

#endif
